module.exports = [{

    data: {
        Title: 'myMixin',

        currentTab2:0,
        navScrollLeftchidl:0,

        company: [],
        companyIndex: -1,

        showbrand:false,
        brandlist:[],
        brandname:'品牌',
        brand:'',

        showbrandlist:true
    },
    onLoad() {
        this.setData({
            testdata2:6666666
        });
    },



    //点击 品牌
    choosebrand:function (e){
        this.data.showbrand  ? this.setData({ showbrand: false }) : this.setData({ showbrand: true });
    },
    initBrandName:function(){
        this.setData({ brandname:'品牌' });
    },
    setBrandName:function(name){
        if(name == '全部'){
            return '品牌'
        }else{
            return name.toString().length <=3 ? name : name.toString().substring(0,3)+"..."
        }
    },
    setbrand:function(e){
        let name = e.currentTarget.dataset.name;
        let brand = name === '全部' ? '' : name;
        let result = this.packageJson({
            sup_id:this.data.sup_id,
            min:this.data.min,
            max:this.data.max,
            min_rate:this.data.min_rate,
            max_rate:this.data.max_rate,
            brand:brand
        });
        this.scrollTop();
        this.setData({
            showbrand:false,
            brandname: this.setBrandName(name),
        });
        this.requestnav1(result);
    },


    getBrandlist:function(id){
        // let app = getApp();
        // app.func.getPromise(`/classify/brands/${id}`)
        //     .then(([code,res])=>{
        //
        //         this.setData({
        //             showbrandlist : res.data.length > 0
        //         });
        //
        //         let brandlist =  res.data.splice(0,19);
        //         brandlist.unshift('全部');
        //         this.setData({  brandlist:brandlist });
        //     })
    },


    //页面自动滑动到顶部
    scrollTop:function(){
        wx.pageScrollTo({scrollTop: 0, duration: 0});
    },

    // 点击 分类
    setClassify2Init:function(){
        this.setData({  currentTab2:0, navScrollLeftchidl:0 });
    },
    navScrollLeft: function (width) {
        this.setClassify2Init();
        this.setData({
            navScrollLeft: width
        })
    },
    navScrollLeftchidl: function (width) {
        this.setData({
            navScrollLeftchidl: width
        })
    },



    //点击顶部分类
    selected_classify: function (e) {
        this.setData({currentTab: e.currentTarget.dataset.current,selectBox: false});
        this.classifyCenter(e,1);
    },
    // 点击二级分类
    selected_child:function(e){
        this.setData({currentTab2: e.currentTarget.dataset.current});
        this.classifyCenter(e,2);
    },
    //分类 居中
    classifyCenter: function (e, key) {
        this.initBrandName();
        this.scrollTop();
        let that = this;
        let ele = key === 1 ? 'scroll-view' : 'scroll-view-child';
        wx.createSelectorQuery().select(`#${e.currentTarget.id}`).fields({size: true}, function (res) {
            let itemwidth = res.width;
            wx.createSelectorQuery().select(`.${ele}`).fields({size: true, rect: true}, function (res) {
                let left = e.currentTarget.offsetLeft;
                let width =  (left + itemwidth / 2) - res.width / 2;
                key===1 ? that.navScrollLeft(width) : that.navScrollLeftchidl(width);
            }).exec();
        }).exec();
        that.preRequestCheckid(e);
    },


    //选择供应商
    supplierList:function(){
        let app = getApp();
       // ap p.func.getPromise('/supplier/list')
       //      .then(([code,res])=>{
       //          this.setData({
       //              company:res.data
       //          });
       //      })
    },
    bindRegionChange: function (e) {
        this.setData({
            companyIndex: e.detail.value
        });
    },


    //点击筛选
    companyInfoInit:function(){
        this.setData({ companyIndex:-1 });
    },
    chooseindex: function (e) {
        let index = e.currentTarget.dataset.index;
        this.setData({chooseindex: index});
    },


}];
